#include "orderbase.h"

OrderBase::OrderBase()
: m_isTrailStop (false)
, m_highPrice(-100)
, m_lowPrice(1000000)
{
}

void OrderBase::setOrderType(ORDERTYPE type)
{
    m_type = type;
    switch (m_type) {
        case ORDERBUY:
            m_strType = "buy";
            break;
        case ORDERSELL:
            m_strType = "sell";
            break;
        case ORDERBUYLIMIT:
            m_strType = "buy limit";
            break;
        case ORDERSELLLIMIT:
            m_strType = "sell limit";
            break;
    }
}

int OrderBase::getNewNo()
{
    int no;
    FILE *file = fopen("orderNo.txt", "r");
    if (!file) {
        no = 0;
    }
    else {
        if (feof(file)) {
            no = 0;
        }
        else {
            fscanf(file, "%d", &no);
        }
        fclose(file);
    }
    no++;
    file = fopen("orderNo.txt", "w");
    if (file) {
        fprintf(file, "%d", no);
        fclose(file);
    }
    return no;
}